package com.example.controller;

import com.example.entity.BrandEntity;
import com.example.valid.AddGroup;
import com.example.entity.StudentGroupDto;
import com.example.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 测试
 * </p>
 *
 * @author MrWen
 **/
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户测试")
public class UserController {


    @PostMapping("/save")
    @ApiOperation("对象属性校验")
    public String save(@RequestBody @Valid User user) {
        log.info("save...user={}", user);
        return "save success";
    }

    @RequestMapping("/save1")
    public void save(@Validated StudentGroupDto studentGroupDto) {

    }

    /**
     * 指定校验分组@Validated({AddGroup.class})，不加分组不生效;未指定校验分组@Validated，不加分组生效
     */
    @PostMapping("/save2")
    public void save(@Validated({AddGroup.class}) @RequestBody BrandEntity brand) {
    }

}
